WOLF core
WOLF: A Modular Estimation Framework for Robotics
XXXXXXXXXXXXXXXXXXXXXXXXvoid(0)" frameborder="0" name="MSearchResults" id="MSearchResults">
map_base.h
Go to the documentation of this file.
1// WOLF - Copyright (C) 2020-2026
2// Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
3// Authors: Joan Solà Ortega (jsola@iri.upc.edu) and
4// Joan Vallvé Navarro (jvallve@iri.upc.edu)
5// All rights reserved.
6//
7// This file is part of WOLF: http://www.iri.upc.edu/wolf
8// WOLF is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License version 3
10// as published by the Free Software Foundation.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19#pragma once
20
21// Fwd refs
22namespace wolf
23{
24class Problem;
25} // namespace wolf
26
27// Wolf includes
28#include "core/common/wolf.h"
33
34// other includes
35#include "yaml-schema-cpp/yaml_server.hpp"
36
37namespace wolf
38{
39/*
40 * Macro for defining Autoconf map creator.
41 *
42 * Place a call to this macro inside your class declaration (in the map_class.h file),
43 * preferably just after the constructors. Inside 'public' keyword.
44 *
45 * In order to use this macro, the derived map class, MapClass,
46 * must have a constructor available with the API:
47 *
48 * MapClass(const YAML::Node& _params);
49 *
50 * Also, there should be the schema file 'MapClass.schema' containing the specifications
51 * of the user input yaml file.
52 *
53 * NOTE: We use `new` and not `make_shared` since the constructor may (should) be private/protected
54 */
55#define WOLF_MAP_CREATE(MapClass) \
56 static MapBasePtr create(const YAML::Node& _input_node, const std::vector<std::string>& _folders_schema = {}) \
57 { \
58 MapBasePtr map; \
59 if (not _folders_schema.empty()) \
60 { \
61 auto server = yaml_schema_cpp::YamlServer(_folders_schema); \
62 server.setYaml(_input_node); \
63 if (not server.applySchema(#MapClass)) \
64 { \
65 WOLF_ERROR(server.getLog()); \
66 return nullptr; \
67 } \
68 map = std::shared_ptr<MapClass>(new MapClass(server.getNode())); \
69 } \
70 else \
71 map = std::shared_ptr<MapClass>(new MapClass(_input_node)); \
72 if (_input_node["landmarks"]) \
73 { \
74 for (unsigned int i = 0; i < _input_node["landmarks"].size(); i++) \
75 { \
76 LandmarkBasePtr lmk_ptr = \
77 FactoryLandmark::create(_input_node["landmarks"][i]["type"].as<std::string>(), \
78 _input_node["landmarks"][i], \
79 _folders_schema); \
80 lmk_ptr->link(map); \
81 } \
82 } \
83 return map; \
84 } \
85 static MapBasePtr create(const std::string& _yaml_filepath, const std::vector<std::string>& _folders_schema) \
86 { \
87 auto server = yaml_schema_cpp::YamlServer(_folders_schema, _yaml_filepath); \
88 if (not server.applySchema(#MapClass)) \
89 { \
90 WOLF_ERROR(server.getLog()); \
91 return nullptr; \
92 } \
93 return create(server.getNode(), {}); \
94 }
95
98class MapBase : public NodeBase, public std::enable_shared_from_this<MapBase>
99{
100 friend LandmarkBase;
101
102 private:
103 LandmarkBasePtrList landmark_list_;
104
105 protected:
108 MapBase();
109
112 MapBase(const YAML::Node& _params);
113
116 MapBase(const std::string& _type, const YAML::Node& _params);
117
118 public:
120
121 ~MapBase() override = default;
122 bool hasChildren() const override;
123
124 protected:
127 virtual LandmarkBasePtr addLandmark(LandmarkBasePtr _landmark_ptr);
128
131 virtual void removeLandmark(LandmarkBasePtr _landmark_ptr);
132
133 public:
136 LandmarkBaseConstPtrList getLandmarkList() const;
137
140 LandmarkBasePtrList getLandmarkList();
141
144 LandmarkBaseConstPtr getLandmark(const unsigned int& _id) const;
145
148 LandmarkBasePtr getLandmark(const unsigned int& _id);
149
152 virtual void load(std::string _map_file_yaml);
153
156 virtual bool save(std::string _map_file_yaml, const std::string& _map_name = "") const;
157
160 virtual void printHeader(int depth, //
161 bool factored_by, //
162 bool metric, //
163 bool state_blocks,
164 std::ostream& stream,
165 std::string _tabs = "") const;
166
169 virtual void print(int depth, //
170 bool factored_by, //
171 bool metric, //
172 bool state_blocks,
173 std::ostream& stream = std::cout,
174 std::string _tabs = "") const;
175
178 virtual CheckLog localCheck(bool _verbose, std::ostream& _stream, std::string _tabs = "") const;
179
182 virtual bool check(CheckLog& _log, bool _verbose, std::ostream& _stream, std::string _tabs = "") const;
183};
184
185inline LandmarkBaseConstPtrList MapBase::getLandmarkList() const
186{
187 LandmarkBaseConstPtrList list_const;
188 for (auto&& obj_ptr : landmark_list_) list_const.push_back(obj_ptr);
189 return list_const;
190}
191
192inline LandmarkBasePtrList MapBase::getLandmarkList()
193{
194 return landmark_list_;
195}
196
197} // namespace wolf
Log of a consistency check: whether it is consistent and the explanation of the inconsistencies.
Definition: check_log.h:30
Base class of landmarks: elements of the map with state blocks, observed from the frames.
Definition: landmark_base.h:93
Base class of maps: container of the landmarks.
Definition: map_base.h:99
virtual bool check(CheckLog &_log, bool _verbose, std::ostream &_stream, std::string _tabs="") const
Checks the consistency of this node and its children, composing the log.
Definition: map_base.cpp:167
~MapBase() override=default
MapBase()
Default constructor.
Definition: map_base.cpp:29
virtual void print(int depth, bool factored_by, bool metric, bool state_blocks, std::ostream &stream=std::cout, std::string _tabs="") const
Prints this node and, depending on the depth, its children.
Definition: map_base.cpp:139
virtual bool save(std::string _map_file_yaml, const std::string &_map_name="") const
Saves the landmarks to a YAML map file. Returns whether it succeeded.
Definition: map_base.cpp:91
virtual CheckLog localCheck(bool _verbose, std::ostream &_stream, std::string _tabs="") const
Checks the consistency of this node (not of its children)
Definition: map_base.cpp:152
virtual void printHeader(int depth, bool factored_by, bool metric, bool state_blocks, std::ostream &stream, std::string _tabs="") const
Prints the information of this node (not of its children)
Definition: map_base.cpp:128
LandmarkBaseConstPtr getLandmark(const unsigned int &_id) const
Returns the landmark with a given id (nullptr if not found)
Definition: map_base.cpp:51
WOLF_MAP_CREATE(MapBase)
LandmarkBaseConstPtrList getLandmarkList() const
Returns the landmarks of the map.
Definition: map_base.h:185
virtual LandmarkBasePtr addLandmark(LandmarkBasePtr _landmark_ptr)
Adds a landmark to the list of landmarks.
Definition: map_base.cpp:40
virtual void removeLandmark(LandmarkBasePtr _landmark_ptr)
Removes a landmark from the list of landmarks.
Definition: map_base.cpp:46
bool hasChildren() const override
Returns whether the node has children in the Wolf tree.
Definition: map_base.cpp:35
virtual void load(std::string _map_file_yaml)
Creates the landmarks of a YAML map file and links them to the map.
Definition: map_base.cpp:69
Base class for Nodes.
Definition: node_base.h:73
Definition: capture_base.h:23